package com.example.qy_hd_demo.service.impl;

import com.example.qy_hd_demo.dao.HtMenuDao;
import com.example.qy_hd_demo.entity.HtMenu;
import com.example.qy_hd_demo.service.HtMenuService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * (HtMenu)表服务实现类
 *
 * @author zhangsw
 * @since 2020-12-21 17:17:14
 */
@Service("htMenuService")
public class HtMenuServiceImpl implements HtMenuService {
    @Resource
    private HtMenuDao htMenuDao;

    /**
     * 通过ID查询单条数据
     *
     * @param menuId 主键
     * @return 实例对象
     */
    @Override
    public HtMenu queryById(Integer menuId) {
        boolean empty = CollectionUtils.isEmpty(new ArrayList<>());
        return this.htMenuDao.queryById(menuId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<HtMenu> queryAllByLimit(int offset, int limit) {
        return this.htMenuDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param htMenu 实例对象
     * @return 实例对象
     */
    @Override
    public HtMenu insert(HtMenu htMenu) {
        this.htMenuDao.insert(htMenu);
        return htMenu;
    }

    /**
     * 修改数据
     *
     * @param htMenu 实例对象
     * @return 实例对象
     */
    @Override
    public HtMenu update(HtMenu htMenu) {
        this.htMenuDao.update(htMenu);
        return this.queryById(htMenu.getMenuId());
    }

    /**
     * 通过主键删除数据
     *
     * @param menuId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer menuId) {
        return this.htMenuDao.deleteById(menuId) > 0;
    }
}